////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include "Test_CoreGameImpl.hpp"

#include <SmegCore/Math/Math.hpp>

////////////////////////////////////////////////////////////
/// Constructor
////////////////////////////////////////////////////////////
Test_CoreGameImpl::Test_CoreGameImpl() :
    DefaultGameImpl(),
    m_pMovableEntity(NULL)
{
}

////////////////////////////////////////////////////////////
/// Destructor
////////////////////////////////////////////////////////////
Test_CoreGameImpl::~Test_CoreGameImpl()
{
}

////////////////////////////////////////////////////////////
/// Init the game
////////////////////////////////////////////////////////////
void Test_CoreGameImpl::Init( sf::RenderWindow* _pRenderWindow ) {
    DefaultGameImpl::Init( _pRenderWindow );

    m_pMovableEntity = new smeg::core::MovableEntity();
    m_pMovableEntity->SetHeading( sf::Vector2f( 1.0f, 0.0f ) );
    m_pMovableEntity->SetMaxTurnRate( 45.0f );
}

////////////////////////////////////////////////////////////
/// DeInit the game
////////////////////////////////////////////////////////////
void Test_CoreGameImpl::DeInit() {
    DefaultGameImpl::DeInit();

    m_pMovableEntity = NULL;
}

////////////////////////////////////////////////////////////
/// Manage an incoming event
////////////////////////////////////////////////////////////
void Test_CoreGameImpl::ManageEvent( const sf::Event& _Event ) {
    DefaultGameImpl::ManageEvent( _Event );
    
    switch ( _Event.type ) {
    case sf::Event::KeyPressed:
        switch (_Event.key.code) {
        case sf::Keyboard::Numpad0:
            std::cout << "*****************************************************************" << std::endl;
            m_pMovableEntity->RotateHeadingToFacePosition( sf::Vector2f( 1.0f, 0.0f ) );
            std::cout << "Facing position ( 1.0f, 0.0f ) => " << "( " << m_pMovableEntity->GetHeading().x << ", " << m_pMovableEntity->GetHeading().y << " )" << std::endl;
            break;
        case sf::Keyboard::Numpad1:
            std::cout << "*****************************************************************" << std::endl;
            m_pMovableEntity->RotateHeadingToFacePosition( sf::Vector2f( 0.0f, 1.0f ) );
            std::cout << "Facing position ( 0.0f, 1.0f ) => " << "( " << m_pMovableEntity->GetHeading().x << ", " << m_pMovableEntity->GetHeading().y << " )" << std::endl;
            break;
        case sf::Keyboard::Numpad2:
            std::cout << "*****************************************************************" << std::endl;
            m_pMovableEntity->RotateHeadingToFacePosition( sf::Vector2f( -1.0f, 0.0f ) );
            std::cout << "Facing position ( -1.0f, 0.0f ) => " << "( " << m_pMovableEntity->GetHeading().x << ", " << m_pMovableEntity->GetHeading().y << " )" << std::endl;
            break;
        case sf::Keyboard::Numpad3:
            std::cout << "*****************************************************************" << std::endl;
            m_pMovableEntity->RotateHeadingToFacePosition( sf::Vector2f( 0.0f, -1.0f ) );
            std::cout << "Facing position ( 0.0f, -1.0f ) => " << "( " << m_pMovableEntity->GetHeading().x << ", " << m_pMovableEntity->GetHeading().y << " )" << std::endl;
            break;
            
        case sf::Keyboard::Numpad4:
            std::cout << "*****************************************************************" << std::endl;
            m_pMovableEntity->RotateHeadingToFacePosition( sf::Vector2f( 1.0f, 1.0f ) );
            std::cout << "Facing position ( 1.0f, 1.0f ) => " << "( " << m_pMovableEntity->GetHeading().x << ", " << m_pMovableEntity->GetHeading().y << " )" << std::endl;
            break;
        case sf::Keyboard::Numpad5:
            std::cout << "*****************************************************************" << std::endl;
            m_pMovableEntity->RotateHeadingToFacePosition( sf::Vector2f( -1.0f, 1.0f ) );
            std::cout << "Facing position ( -1.0f, 1.0f ) => " << "( " << m_pMovableEntity->GetHeading().x << ", " << m_pMovableEntity->GetHeading().y << " )" << std::endl;
            break;
        case sf::Keyboard::Numpad6:
            std::cout << "*****************************************************************" << std::endl;
            m_pMovableEntity->RotateHeadingToFacePosition( sf::Vector2f( -1.0f, -1.0f ) );
            std::cout << "Facing position ( -1.0f, -1.0f ) => " << "( " << m_pMovableEntity->GetHeading().x << ", " << m_pMovableEntity->GetHeading().y << " )" << std::endl;
            break;
        case sf::Keyboard::Numpad7:
            std::cout << "*****************************************************************" << std::endl;
            m_pMovableEntity->RotateHeadingToFacePosition( sf::Vector2f( 1.0f, -1.0f ) );
            std::cout << "Facing position ( 1.0f, -1.0f ) => " << "( " << m_pMovableEntity->GetHeading().x << ", " << m_pMovableEntity->GetHeading().y << " )" << std::endl;
            break;
        }
    }
}

////////////////////////////////////////////////////////////
/// Call all the Update in the other systems
////////////////////////////////////////////////////////////
void Test_CoreGameImpl::Update( float _fDeltaTime ) {
    DefaultGameImpl::Update( _fDeltaTime );
}

////////////////////////////////////////////////////////////
/// Call all the Render in the other systems
////////////////////////////////////////////////////////////
void Test_CoreGameImpl::Render() {
    DefaultGameImpl::Render();
}